<template>
    <div class="app-container">
        <!-- 顶部导航 -->
        <header class="app-header">
            <div class="header-content">
                <button class="back-btn" @click="goBack">←</button>
                <h1>账户设置</h1>
                <button class="theme-btn" @click="toggleDarkMode">
                    {{ isDarkMode ? '☀️' : '🌙' }}
                </button>
            </div>
        </header>

        <div class="main-container">
            <!-- 侧边导航 -->
            <aside class="sidebar">
                <nav class="nav-list">
                    <button v-for="(item, index) in navItems" :key="index" @click="activeTab = index"
                        :class="['nav-item', activeTab === index ? 'active' : '']">
                        <span class="nav-icon">{{ item.icon }}</span>
                        <span class="nav-text">{{ item.title }}</span>
                    </button>
                </nav>
            </aside>

            <!-- 主内容区 -->
            <main class="content-area">
                <!-- 个人资料 -->
                <div v-if="activeTab === 0" class="setting-panel">
                    <h2 class="panel-title">个人资料</h2>

                    <div class="avatar-section">
                        <div class="avatar-container">
                            <img :src="userAvatar" alt="用户头像" class="avatar-img">
                            <label class="avatar-upload" :style="{ pointerEvents: avatarUploading ? 'none' : 'auto' }">
                                <span>{{ avatarUploading ? '上传中...' : '📷' }}</span>
                                <!-- 确保input无disabled，且类型正确 -->
                                <input ref="avatarInput"  type="file" accept="image/*" @change="handleAvatarChange" />
                            </label>
                        </div>
                        <div class="avatar-info">
                            <div class="username">{{ username }}</div>
                            <div class="account">账号: {{ account }}</div>
                            <div class="avatar-hint">点击头像可更换</div>
                            <!-- 上传状态提示 -->
                            <div v-if="avatarUploadMsg" class="avatar-upload-msg">{{ avatarUploadMsg }}</div>
                        </div>
                    </div>

                    <form class="profile-form" @submit.prevent="handleProfileSubmit">
                        <div class="form-group">
                            <label class="form-label">昵称</label>
                            <input type="text" v-model="userNickname" class="form-input" placeholder="请输入昵称" required>
                        </div>

                        <div class="form-group">
                            <label class="form-label">个性签名</label>
                            <textarea v-model="userBio" class="form-textarea" placeholder="说点什么..." rows="3"></textarea>
                        </div>

                        <div class="form-group">
                            <label class="form-label">性别</label>
                            <div class="radio-group">
                                <label class="radio-item">
                                    <input type="radio" name="gender" value="male" v-model="userGender" required>
                                    <span>男</span>
                                </label>
                                <label class="radio-item">
                                    <input type="radio" name="gender" value="female" v-model="userGender">
                                    <span>女</span>
                                </label>
                                <label class="radio-item">
                                    <input type="radio" name="gender" value="secret" v-model="userGender">
                                    <span>保密</span>
                                </label>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="form-label">生日</label>
                            <input type="date" v-model="userBirthday" class="form-input">
                        </div>

                        <div class="form-actions">
                            <button type="submit" class="btn primary-btn" :disabled="isSaving || avatarUploading">
                                {{ isSaving ? '保存中...' : '保存修改' }}
                            </button>
                        </div>
                    </form>
                </div>

                <!-- 安全设置 -->
                <div v-if="activeTab === 1" class="setting-panel">
                    <h2 class="panel-title">安全设置</h2>

                    <div class="setting-list">
                        <button class="setting-item" @click="showChangePassword = true">
                            <div class="setting-icon">🔒</div>
                            <div class="setting-info">
                                <div class="setting-title">修改密码</div>
                                <div class="setting-desc">定期修改密码可提高账号安全性</div>
                            </div>
                            <div class="setting-arrow">→</div>
                        </button>

                        <div class="setting-item">
                            <div class="setting-icon">📱</div>
                            <div class="setting-info">
                                <div class="setting-title">手机号码</div>
                                <div class="setting-desc">{{ userPhone || '未绑定' }}</div>
                            </div>
                            <button class="setting-action">
                                {{ userPhone ? '更换' : '绑定' }}
                            </button>
                        </div>

                        <div class="setting-item">
                            <div class="setting-icon">✉️</div>
                            <div class="setting-info">
                                <div class="setting-title">电子邮箱</div>
                                <div class="setting-desc">{{ userEmail || '未绑定' }}</div>
                            </div>
                            <button class="setting-action">
                                {{ userEmail ? '更换' : '绑定' }}
                            </button>
                        </div>

                        <div class="setting-item">
                            <div class="setting-icon">🛡️</div>
                            <div class="setting-info">
                                <div class="setting-title">登录保护</div>
                                <div class="setting-desc">{{ loginProtection ? '已开启' : '未开启' }}</div>
                            </div>
                            <label class="toggle-switch">
                                <input type="checkbox" v-model="loginProtection" class="toggle-input">
                                <span class="toggle-slider"></span>
                            </label>
                        </div>
                    </div>
                </div>

                <!-- 隐私设置 -->
                <div v-if="activeTab === 2" class="setting-panel">
                    <h2 class="panel-title">隐私设置</h2>
                    <div class="setting-section">
                        <h3 class="section-title">好友申请设置</h3>
                        <select v-model="friendRequestSetting" class="form-input">
                            <option value="anyone">任何人可添加我为好友</option>
                            <option value="verify">需要验证信息</option>
                            <option value="question">需要回答问题</option>
                            <option value="reject">拒绝所有好友申请</option>
                        </select>
                    </div>
                </div>

                <!-- 通知设置 -->
                <div v-if="activeTab === 3" class="setting-panel">
                    <h2 class="panel-title">通知设置</h2>
                    <div class="setting-list">
                        <div class="setting-item">
                            <div class="setting-icon">💬</div>
                            <div class="setting-info">
                                <div class="setting-title">新消息通知</div>
                                <div class="setting-desc">收到新消息时推送通知</div>
                            </div>
                            <label class="toggle-switch">
                                <input type="checkbox" v-model="notifications.newMessage" class="toggle-input">
                                <span class="toggle-slider"></span>
                            </label>
                        </div>
                    </div>
                </div>

                <!-- 关于 -->
                <div v-if="activeTab === 4" class="setting-panel">
                    <h2 class="panel-title">关于</h2>
                    <div class="logout-section">
                        <button class="logout-btn" @click="handleLogout">
                            退出登录
                        </button>
                    </div>
                </div>
            </main>
        </div>

        <!-- 底部导航（移动端） -->
        <nav class="bottom-nav">
            <button v-for="(item, index) in navItems" :key="index" @click="activeTab = index"
                :class="['nav-btn', activeTab === index ? 'active' : '']">
                <span class="nav-btn-icon">{{ item.icon }}</span>
                <span class="nav-btn-text">{{ item.title }}</span>
            </button>
        </nav>

        <!-- 修改密码弹窗 -->
        <div v-if="showChangePassword" class="modal-overlay">
            <div class="modal-container">
                <div class="modal-header">
                    <h3>修改密码</h3>
                    <button class="modal-close" @click="showChangePassword = false">×</button>
                </div>
                <form class="modal-form" @submit.prevent="handleChangePassword">
                    <div class="form-group">
                        <label class="form-label">当前密码</label>
                        <input type="password" v-model="oldPassword" class="form-input" required placeholder="请输入当前密码">
                    </div>
                    <div class="form-group">
                        <label class="form-label">新密码</label>
                        <input type="password" v-model="newPassword" class="form-input" required minlength="6"
                            placeholder="请输入6-20位新密码">
                    </div>
                    <div class="form-group">
                        <label class="form-label">确认新密码</label>
                        <input type="password" v-model="confirmPassword" class="form-input">
                    </div>
                    <div class="form-actions">
                        <button type="button" class="btn secondary-btn" @click="showChangePassword = false">
                            取消
                        </button>
                        <button type="submit" class="btn primary-btn" :disabled="isChangingPassword">
                            {{ isChangingPassword ? '修改中...' : '确认修改' }}
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</template>

<script>
import { ElMessage } from 'element-plus';
import request from '@/utils/request';

export default {
    name: 'AccountSettings',
    data() {
        return {
            navItems: [
                { title: '个人资料', icon: '👤' },
                { title: '安全设置', icon: '🔒' },
                { title: '隐私设置', icon: '🔐' },
                { title: '通知设置', icon: '🔔' },
                { title: '关于', icon: 'ℹ️' }
            ],
            activeTab: 0,
            userAvatar: 'https://picsum.photos/id/64/200/200',
            username: '测试用户',
            account: 'test123',
            userNickname: '',
            userBio: '',
            userGender: 'secret',
            userBirthday: '',
            userPhone: '',
            userEmail: '',
            loginProtection: false,
            showChangePassword: false,
            oldPassword: '',
            newPassword: '',
            confirmPassword: '',
            friendRequestSetting: 'verify',
            notifications: { newMessage: true },
            isDarkMode: false,
            // 上传相关状态（重点新增/修改）
            isSaving: false,          // 资料保存加载状态
            avatarUploading: false,   // 头像上传加载状态
            ossAvatarUrl: '',         // OSS返回的头像URL（关键：用于保存到资料）
            isChangingPassword: false, // 密码修改加载状态
            avatarUploadMsg: ''       // 头像上传提示信息（成功/失败）
        };
    },
    created() {
        this.fetchUserInfo();
        this.initTheme();
    },
    methods: {
        async fetchUserInfo() {
            try {
                const response = await request.get('/user/info');
                const userData = response.data;
                const currentUserStr = localStorage.getItem('currentUser');
                const currentUser = currentUserStr ? JSON.parse(currentUserStr) : {};
                
                // 赋值用户信息
                this.username = currentUser.name || '未知用户';
                this.account = currentUser.maskedPhone || '未知账号';
                this.userNickname = userData.nickname || '';
                this.userBio = userData.bio || '这个人很懒，什么都没留下';
                this.userGender = userData.gender || 'secret';
                this.userBirthday = userData.birthday || '';
                this.userPhone = userData.phone || '';
                this.userEmail = userData.email || '';
                this.loginProtection = userData.loginProtection || false;
                this.friendRequestSetting = userData.friendRequestSetting || 'verify';
                this.notifications.newMessage = userData.notifications?.newMessage ?? true;
                // 初始化头像（优先用后端返回的OSS头像）
                this.userAvatar = userData.avatar || this.userAvatar;
                this.ossAvatarUrl = userData.avatar || '';
            } catch (error) {
                console.error('获取用户信息失败：', error);
                ElMessage.error(`加载失败：${error.msg || '请稍后重试'}`);
            }
        },

        goBack() {
            this.$router.push('/home');
            ElMessage.success('已返回首页');
        },

        initTheme() {
            const isDark = localStorage.getItem('isDarkMode') === 'true';
            this.isDarkMode = isDark;
            if (isDark) document.documentElement.classList.add('dark-mode');
        },

        toggleDarkMode() {
            this.isDarkMode = !this.isDarkMode;
            localStorage.setItem('isDarkMode', this.isDarkMode);
            document.documentElement.classList.toggle('dark-mode');
            ElMessage.info(`已切换至${this.isDarkMode ? '深色' : '浅色'}模式`);
        },

        // 头像上传到OSS（重点修改：解决file为空问题，增加调试日志）
        async handleAvatarChange(e) {
            // 1. 清空之前的上传提示
            this.avatarUploadMsg = '';
            // 2. 强制获取input元素（避免事件对象异常）
            const fileInput = this.$refs.avatarInput;
            if (!fileInput || !fileInput.files || fileInput.files.length === 0) {
                this.avatarUploadMsg = '未选择文件，请重新选择';
                console.warn('文件输入异常：未获取到文件列表');
                return;
            }

            // 3. 获取文件对象（核心：确保是File类型）
            const file = fileInput.files[0];
            console.log('选中的文件详情：', file); // 调试：确认file是File对象，而非{}
            if (!(file instanceof File)) {
                this.avatarUploadMsg = '文件格式异常，请选择图片文件';
                ElMessage.error('文件格式异常');
                return;
            }

            // 4. 文件验证（类型+大小）
            const isImage = file.type.startsWith('image/');
            const isLt5M = file.size / 1024 / 1024 < 5;
            if (!isImage) {
                this.avatarUploadMsg = '仅支持图片文件（JPG/PNG/GIF等）';
                ElMessage.error(this.avatarUploadMsg);
                fileInput.value = ''; // 清空输入
                return;
            }
            if (!isLt5M) {
                this.avatarUploadMsg = `图片大小超过5MB（当前${(file.size/1024/1024).toFixed(2)}MB）`;
                ElMessage.error(this.avatarUploadMsg);
                fileInput.value = '';
                return;
            }

            try {
                this.avatarUploading = true;
                this.avatarUploadMsg = '正在上传...';

                // 5. 构造FormData（关键：仅添加File对象，不手动设置Content-Type）
                const formData = new FormData();
                formData.append('file', file); // 键名"file"必须与后端@RequestParam("file")一致
                formData.append('originalFilename', file.name); // 可选：后端也可通过file.getOriginalFilename()获取

                // 调试：打印FormData内容，确认file正确添加
                console.log('FormData内容：');
                for (const [key, value] of formData.entries()) {
                    console.log(`  ${key}:`, value); // 正常应显示"file: File {name: ..., size: ...}"
                }

                // 6. 发送上传请求（重点：不手动设置Content-Type，让浏览器自动处理）
                const response = await request.post('/oss/upload-avatar', formData, {
                    headers: {
                        'Content-Type': 'multipart/form-data'
                    },
                    onUploadProgress: (progressEvent) => {
                        const progress = Math.round((progressEvent.loaded / progressEvent.total) * 100);
                        this.avatarUploadMsg = `正在上传...${progress}%`;
                        console.log(`上传进度：${progress}%`);
                    }
                });

                // 7. 处理上传响应（核心：获取OSS头像URL）
                console.log('上传接口响应：', response);
                if (response.code === 1) {
                    this.ossAvatarUrl = response.data; // 保存OSS返回的头像URL
                    this.userAvatar = this.ossAvatarUrl; // 实时更新头像预览
                    this.avatarUploadMsg = '头像上传成功！';
                    ElMessage.success('头像上传成功');
                } else {
                    this.avatarUploadMsg = `上传失败：${response.msg || '接口返回异常'}`;
                    ElMessage.error(this.avatarUploadMsg);
                }
            } catch (error) {
                // 8. 捕获网络/代码异常
                this.avatarUploadMsg = `上传失败：${error.message || '网络异常'}`;
                ElMessage.error(this.avatarUploadMsg);
                console.error('头像上传异常：', error);
            } finally {
                this.avatarUploading = false;
                fileInput.value = ''; // 清空输入，允许重新选择同一文件
            }
        },

        // 提交个人资料（含OSS头像URL）
        async handleProfileSubmit() {
            try {
                this.isSaving = true;

                // 1. 验证必要信息
                if (!this.userNickname.trim()) {
                    ElMessage.error('请输入昵称');
                    this.isSaving = false;
                    return;
                }

                // 2. 收集提交数据（重点：包含ossAvatarUrl）
                const profileData = {
                    nickname: this.userNickname.trim(),
                    bio: this.userBio.trim(),
                    gender: this.userGender,
                    birthday: this.userBirthday,
                    avatar: this.ossAvatarUrl // 关键：将OSS头像URL传给后端
                };
                console.log('提交的个人资料：', profileData);

                // 3. 发送保存请求
                const response = await request.post('/user/update-profile', profileData);

                // 4. 处理保存响应
                if (response.code === 1) {
                    ElMessage.success('个人资料更新成功');
                    this.fetchUserInfo(); // 重新拉取用户信息，刷新页面
                } else {
                    ElMessage.error(`更新失败：${response.msg || '接口返回异常'}`);
                }
            } catch (error) {
                ElMessage.error(`更新失败：${error.message || '网络异常'}`);
                console.error('资料提交异常：', error);
            } finally {
                this.isSaving = false;
            }
        },

        // 处理密码修改
        async handleChangePassword() {
            if (this.newPassword !== this.confirmPassword) {
                return ElMessage.error('两次输入的新密码不一致');
            }
            if (this.newPassword.length < 6) {
                return ElMessage.error('新密码长度不能少于6位');
            }

            try {
                this.isChangingPassword = true;
                const response = await request.post('/user/change-password', {
                    oldPassword: this.oldPassword,
                    newPassword: this.newPassword
                });

                if (response.code === 200) {
                    ElMessage.success('密码修改成功，请重新登录');
                    this.showChangePassword = false;
                    this.handleLogout();
                } else {
                    ElMessage.error(`修改失败：${response.msg || '接口返回异常'}`);
                }
            } catch (error) {
                ElMessage.error(`修改失败：${error.message || '网络异常'}`);
                console.error('密码修改异常：', error);
            } finally {
                this.isChangingPassword = false;
                // 清空密码输入
                this.oldPassword = '';
                this.newPassword = '';
                this.confirmPassword = '';
            }
        },

        handleLogout() {
            if (confirm('确定要退出登录吗？')) {
                localStorage.removeItem('userToken');
                localStorage.removeItem('currentUser');
                ElMessage.success('已退出登录');
                this.$router.push('/login');
            }
        }
    }
};
</script>

<style>
/* 基础样式保持不变，新增/修改上传提示样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
    background-color: #f5f5f5;
    color: #333;
    transition: background-color 0.3s, color 0.3s;
}

body.dark-mode {
    background-color: #1a1a1a;
    color: #f8f8f8;
}

.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* 顶部导航 */
.app-header {
    background-color: white;
    border-bottom: 1px solid #eee;
    padding: 12px 0;
    transition: all 0.3s;
}

.dark-mode .app-header {
    background-color: #2d2d2d;
    border-color: #444;
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.back-btn,
.theme-btn {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
    color: inherit;
}

.back-btn:hover,
.theme-btn:hover {
    background-color: #f0f0f0;
}

.dark-mode .back-btn:hover,
.dark-mode .theme-btn:hover {
    background-color: #444;
}

.header-content h1 {
    font-size: 18px;
    font-weight: 600;
}

/* 主容器 */
.main-container {
    display: flex;
    flex: 1;
}

/* 侧边栏 */
.sidebar {
    width: 200px;
    background-color: white;
    border-right: 1px solid #eee;
    transition: all 0.3s;
}

.dark-mode .sidebar {
    background-color: #2d2d2d;
    border-color: #444;
}

.nav-list {
    list-style: none;
}

.nav-item {
    width: 100%;
    padding: 14px 20px;
    background: none;
    border: none;
    display: flex;
    align-items: center;
    cursor: pointer;
    transition: background-color 0.2s;
    text-align: left;
    color: inherit;
}

.nav-item:hover {
    background-color: #f5f5f5;
}

.dark-mode .nav-item:hover {
    background-color: #383838;
}

.nav-item.active {
    background-color: #e8f0fe;
    color: #1976d2;
}

.dark-mode .nav-item.active {
    background-color: #1a365d;
    color: #81c7fe;
}

.nav-icon {
    margin-right: 10px;
    font-size: 18px;
}

.nav-text {
    font-size: 14px;
    font-weight: 500;
}

/* 内容区 */
.content-area {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
}

.setting-panel {
    background-color: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    padding: 20px;
    margin-bottom: 20px;
    transition: all 0.3s;
}

.dark-mode .setting-panel {
    background-color: #2d2d2d;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

.panel-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid #eee;
    color: inherit;
}

.dark-mode .panel-title {
    border-color: #444;
}

/* 头像区域 */
.avatar-section {
    display: flex;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 1px solid #eee;
    transition: border-color 0.3s;
}

.dark-mode .avatar-section {
    border-color: #444;
}

.avatar-container {
    position: relative;
    margin-right: 20px;
}

.avatar-img {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #eee;
    transition: border-color 0.3s;
}

.dark-mode .avatar-img {
    border-color: #444;
}

.avatar-upload {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 30px;
    height: 30px;
    background-color: #1976d2;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.2s;
}

.avatar-upload:hover {
    background-color: #1565c0;
}

.avatar-upload input {
    display: none;
}

.avatar-info {
    flex: 1;
}

.username {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 5px;
}

.account {
    color: #666;
    font-size: 14px;
    margin-bottom: 5px;
}

.dark-mode .account {
    color: #bbb;
}

.avatar-hint {
    color: #999;
    font-size: 12px;
    margin-bottom: 4px;
}

.dark-mode .avatar-hint {
    color: #aaa;
}

/* 新增：头像上传提示样式 */
.avatar-upload-msg {
    font-size: 12px;
    color: #1976d2;
}

.dark-mode .avatar-upload-msg {
    color: #81c7fe;
}

/* 表单样式 */
.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    font-size: 14px;
    color: inherit;
}

.form-input,
.form-textarea,
select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    background-color: white;
    transition: all 0.3s;
    color: #333;
}

.dark-mode .form-input,
.dark-mode .form-textarea,
.dark-mode select {
    border-color: #555;
    background-color: #383838;
    color: #f8f8f8;
}

.dark-mode ::placeholder {
    color: #aaa;
    opacity: 1;
}

.form-input:focus,
.form-textarea:focus,
select:focus {
    outline: none;
    border-color: #1976d2;
}

.form-textarea {
    resize: none;
}

.radio-group {
    display: flex;
    gap: 20px;
}

.radio-item {
    display: flex;
    align-items: center;
    cursor: pointer;
    color: inherit;
}

.radio-item input {
    margin-right: 6px;
}

/* 按钮样式 */
.btn {
    padding: 8px 16px;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
    border: none;
}

.primary-btn {
    background-color: #1976d2;
    color: white;
}

.primary-btn:hover {
    background-color: #1565c0;
}

.primary-btn:disabled {
    background-color: #90caf9;
    cursor: not-allowed;
}

.secondary-btn {
    background-color: #f5f5f5;
    color: #333;
}

.dark-mode .secondary-btn {
    background-color: #444;
    color: #f8f8f8;
}

.secondary-btn:hover {
    background-color: #e0e0e0;
}

.dark-mode .secondary-btn:hover {
    background-color: #555;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 30px;
}

/* 安全设置列表 */
.setting-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.setting-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 15px;
    background: none;
    border: 1px solid #eee;
    border-radius: 8px;
    text-align: left;
    cursor: pointer;
    transition: all 0.3s;
    color: inherit;
}

.dark-mode .setting-item {
    border-color: #444;
}

.setting-item:hover {
    background-color: #f5f5f5;
}

.dark-mode .setting-item:hover {
    background-color: #383838;
}

.setting-icon {
    font-size: 20px;
    margin-right: 15px;
    min-width: 24px;
}

.setting-info {
    flex: 1;
}

.setting-title {
    font-weight: 500;
    margin-bottom: 3px;
}

.setting-desc {
    font-size: 12px;
    color: #666;
}

.dark-mode .setting-desc {
    color: #bbb;
}

.setting-arrow {
    color: #999;
    font-size: 16px;
}

.setting-action {
    background: none;
    border: none;
    color: #1976d2;
    cursor: pointer;
    font-size: 14px;
    padding: 5px 10px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.setting-action:hover {
    background-color: #e8f0fe;
}

.dark-mode .setting-action:hover {
    background-color: #1a365d;
}

/* 开关样式 */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 24px;
}

.toggle-input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: 0.4s;
    border-radius: 24px;
}

.dark-mode .toggle-slider {
    background-color: #555;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.4s;
    border-radius: 50%;
}

input:checked+.toggle-slider {
    background-color: #1976d2;
}

input:checked+.toggle-slider:before {
    transform: translateX(26px);
}

/* 弹窗样式 */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-container {
    background-color: white;
    border-radius: 8px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    transition: all 0.3s;
}

.dark-mode .modal-container {
    background-color: #2d2d2d;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid #eee;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: border-color 0.3s;
}

.dark-mode .modal-header {
    border-color: #444;
}

.modal-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: inherit;
}

.modal-close {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
    color: inherit;
}

.modal-close:hover {
    background-color: #f0f0f0;
}

.dark-mode .modal-close:hover {
    background-color: #444;
}

.modal-form {
    padding: 20px;
}

/* 底部导航（移动端） */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: white;
    border-top: 1px solid #eee;
    padding: 5px 0;
    justify-content: space-around;
    z-index: 100;
    transition: all 0.3s;
}

.dark-mode .bottom-nav {
    background-color: #2d2d2d;
    border-top-color: #444;
}

.nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    padding: 5px 10px;
    cursor: pointer;
    color: #666;
    transition: color 0.2s;
}

.dark-mode .nav-btn {
    color: #aaa;
}

.nav-btn.active {
    color: #1976d2;
}

.dark-mode .nav-btn.active {
    color: #81c7fe;
}

.nav-btn-icon {
    font-size: 18px;
    margin-bottom: 3px;
}

.nav-btn-text {
    font-size: 12px;
}

/* 退出登录按钮 */
.logout-section {
    margin-top: 25px;
    padding-top: 20px;
    border-top: 1px solid #eee;
    transition: border-color 0.3s;
}

.dark-mode .logout-section {
    border-color: #444;
}

.logout-btn {
    width: 100%;
    padding: 10px;
    background: none;
    border: 1px solid #ff6b6b;
    color: #ff6b6b;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.logout-btn:hover {
    background-color: #ffebee;
}

.dark-mode .logout-btn {
    border-color: #ff8787;
    color: #ff8787;
}

.dark-mode .logout-btn:hover {
    background-color: #4a1a1a;
}

/* 隐私设置区域 */
.setting-section {
    margin-bottom: 25px;
}

.section-title {
    font-size: 15px;
    font-weight: 500;
    margin-bottom: 12px;
    color: inherit;
}

/* 移动端适配 */
@media (max-width: 768px) {
    .sidebar {
        display: none;
    }

    .bottom-nav {
        display: flex;
    }

    .content-area {
        padding-bottom: 70px;
    }

    .avatar-section {
        flex-direction: column;
        text-align: center;
    }

    .avatar-container {
        margin-right: 0;
        margin-bottom: 15px;
    }

    .avatar-upload-msg {
        display: inline-block;
        margin-top: 8px;
    }
}
</style>